#include "shootscene.h"
#include<stdlib.h>
ShootScene::ShootScene(QObject *parent)
    : QGraphicsScene{parent}
{
    //展示图元
    for(int i = 0;i<16;i++){
        this->Item[i] = new ShootItem;
        this->Item[i]->setPos(i/4 * this->Item[i]->boundingRect().width(),i%4 * this->Item[i]->boundingRect().height());
        this->addItem(this->Item[i]);
    }
    //设置定时器
    this->ptimer = new QTimer;
    connect(this->ptimer,SIGNAL(timeout()),this,SLOT(ShowKND()));
}
void ShootScene::ShowKND(){
    //随机总统数量
    int num = rand()%3+1;
    //重置所有敞篷车
    for(int j = 0;j<16;j++){
        this->Item[j]->SetPic(":/seatsmall.jpg");
        this->Item[j]->KND = 0;
    }
    //生成一个随机数产生总统
    for(int i = 0;i<num;i++){
        int pos = rand()%16;
        this->Item[pos]->SetPic(":/Face.jpeg");
        this->Item[pos]->KND = 1;
    }
}
void ShootScene::GameStart(){
    this->ptimer->start(900);
}
void ShootScene::GameEnd(){
    for(int j = 0;j<16;j++){
        this->Item[j]->SetPic(":/seatsmall.jpg");
        this->Item[j]->KND = 0;
    }
    this->ptimer->stop();
}
